#include "two.h"
#include "one.h"
#include "widget.h"
Two::Two(QWidget *parent) :
    QWidget(parent)
{
    /* 设置主窗体的位置与大小 */
    this->setGeometry(0, 0, 800, 480);

    /* 实例化对象和设置显示位置与大小 */
    dial = new QDial(this);
    dial->setGeometry(300, 100, 200, 200);
    /* 设置页长（两个最大刻度的间距）*/
    dial->setPageStep(10);
    /* 设置刻度可见 */
    dial->setNotchesVisible(true);
    /* 设置两个凹槽之间的目标像素数 */
    dial->setNotchTarget(1.00);
    /* 设置 dial 值的范围 */
    dial->setRange(0,100);
    /* 开启后可指向圆的任何角度 */
    //dial->setWrapping(true);

    /* 实例化对象和设置显示位置与大小 */
    label = new QLabel(this);
    label->setGeometry(370, 300, 200, 50);
    /* 初始化为 0km/h */
    label->setText("0km/h");

    /* 实例化与设置显示的位置大小*/
    lcdNumber = new QLCDNumber(this);
    lcdNumber->setGeometry(670, 400, 100, 50);
    /* 设置显示的位数 8 位 */
    lcdNumber->setDigitCount(8);
    /* 设置样式 */
    lcdNumber->setSegmentStyle(QLCDNumber::Flat);
    /* 设置 lcd 显示为当前系统时间 */
    QTime time = QTime::currentTime();
    /* 设置显示的样式 */
    lcdNumber->display(time.toString("hh:mm:ss"));
    timer = new QTimer(this);
    /* 设置定时器 1000 毫秒发送一个 timeout()信号 */
    timer->start(1000);

    labelString = new QLabel(this);
    labelString->setText("电机参数实时显示界面");
    labelString->setGeometry(300, 50, 250, 20);

    labVolt = new QLabel(this);
    labVolt->setText("电压:");
    labVolt->setGeometry(100, 150, 100, 20);
    Volt = new QLabel (this);
    Volt->setText("连接中····");
    Volt->setGeometry(150, 150, 100, 20);

    labAmpe = new QLabel(this);
    labAmpe->setText("电流:");
    labAmpe->setGeometry(100, 250, 100, 20);
    Ampe = new QLabel (this);
    Ampe->setText("连接中····");
    Ampe->setGeometry(150, 250, 100, 20);

    labTem = new QLabel(this);
    labTem->setText("温度:");
    labTem->setGeometry(600, 150, 100, 20);
    Tem = new QLabel (this);
    Tem->setText("连接中····");
    Tem->setGeometry(650, 150, 100, 20);

    labTor = new QLabel(this);
    labTor->setText("扭矩:");
    labTor->setGeometry(600, 250, 100, 20);
    Tor = new QLabel (this);
    Tor->setText("连接中····");
    Tor->setGeometry(650, 250, 100, 20);

    QFont ft;
    ft.setPointSize(14);
    labelString->setFont(ft);
    labVolt->setFont(ft);
    labAmpe->setFont(ft);
    labTem->setFont(ft);
    labTor->setFont(ft);
    Volt->setFont(ft);
    Ampe->setFont(ft);
    Tem->setFont(ft);
    Tor->setFont(ft);
    label->setFont(ft);


    pushButton1 = new QPushButton(this);
    pushButton1->setGeometry(380, 400, 50, 20);
    pushButton1->setText("连接");
    pushButton2 = new QPushButton(this);
    pushButton2->setGeometry(380, 420, 50, 20);
    pushButton2->setText("取消连接");
    on_previousPushButton = new QPushButton(this);
    on_previousPushButton->setGeometry(0, 430, 50, 20);
    on_previousPushButton->setText("主界面");


    /* 信号槽连接 */
    connect(dial, SIGNAL(valueChanged(int)),this, SLOT(dialValueChanged(int)));
    connect(timer, SIGNAL(timeout()), this,SLOT(timerTimeOut()));
    connect(pushButton1,SIGNAL(clicked()), this,SLOT(pushButton1Clicked()));
    connect(pushButton2,SIGNAL(clicked()), this,SLOT(pushButton2Clicked()));
    connect(on_previousPushButton,SIGNAL(clicked()), this,SLOT(on_previousPushButton_clicked()));
}

Two::~Two()
{

}
void Two::dialValueChanged(int val)
{
    /* QString::number()转换成字符串 */
    label->setText(QString::number(val) + "km/h");
}

void Two::timerTimeOut()
{
    /* 当定时器计时 1000 毫秒后，刷新 lcd 显示当前系统时间 */
    QTime time = QTime::currentTime();
    /* 设置显示的样式 */
    lcdNumber->display(time.toString("hh:mm:ss"));
}

void Two::pushButton1Clicked()
{
     /* 设置 label 里的文本显示内容 */
    Volt->setText("24V");
    Ampe->setText("20.5A");
    Tem->setText("29°C");
    Tor->setText("500N.m");
    dial->setValue(25);
}
void Two::pushButton2Clicked()
{
     /* 设置 label 里的文本显示内容 */
    Volt->setText("连接中····");
    Ampe->setText("连接中····");
    Tem->setText("连接中····");
    Tor->setText("连接中····");
    dial->setValue(0);

}

void Two::on_previousPushButton_clicked()
{
    emit display(0);
}



